<template>
  <div>
    <div class="note_header">
      <div class="note_headtext" v-for="item in story" :key="item.id">
        <i class="iconfont icon-fanhui" @click="prev"></i>
        <div class="img">
          <img :src="item.author.p" alt="" />
        </div>
        <div class="note_user">
          <div>
            <p style="color: #303030">
              {{ item.author.n }} LV.{{ item.author.lvl }}
            </p>
          </div>
          <div>
            <p style="color: #9d9d9d">{{ item.straight_text }}</p>
          </div>
        </div>
        <div class="note_guan">
          <p>关注</p>
        </div>
        <i class="iconfont icon-diandiandian"></i>
      </div>
    </div>

    <div class="note_img">
      <van-swipe @change="onChange">
        <van-swipe-item v-for="(item, index) in images" :key="index">
          <img :src="item.u" />
        </van-swipe-item>
        <template #indicator>
          <div class="custom-indicator">
            {{ current + 1 }}/{{ images.length }}
          </div>
        </template>
      </van-swipe>
    </div>

    <div class="note_name" v-for="item in story" :key="item.id">
      <h2>{{ item.title }}</h2>
      <div class="note_shao">
        <p v-for="(value, index) in item.contents" :key="index">
          <span v-if="value.type == 3" :style="{ color: value.color }"
            ><img :src="value.icon" alt="" /> {{ value.c }}</span
          >
          <span v-else :style="{ color: value.color }">{{ value.c }}</span>
        </p>
      </div>
      <div class="note_time">
        <p>{{ item.publishtime }}</p>
        <p>{{ item.like_count }}次赞</p>
      </div>
    </div>

    <h2 class="h2">相关笔记</h2>
    <div class="node">
      <div class="good" v-for="(item, index) in notelists" :key="index">

         <router-link :to="'/noteils?id='+ item.note.id">
        <div class="good-img" v-if="item.type == 2">
          <div class="img">
            <img :src="item.activity.image" alt="" />
          </div>
          <div class="pull">
            <p>{{ item.activity.name }}</p>
          </div>
          <div class="duo">
            <div class="duo-left">
              <img :src="item.activity.author.p" alt="" />
              <span>{{ item.activity.author.n }}</span>
            </div>
            <div class="duo-right">
              <img :src="item.activity.action_icon" alt="" />
              <span>{{ item.activity.action_title }}</span>
            </div>
          </div>
        </div>

        <div class="good-img" v-if="item.type == 1">
          <div class="img">
            <img :src="item.note.image_u" alt="" />
          </div>
          <div class="pull">
            <p>{{ item.note.title }}</p>
          </div>
          <div class="duo">
            <div class="duo-left">
              <img :src="item.note.author.p" alt="" />
              <span>{{ item.note.author.n }}</span>
            </div>
            <div class="duo-right">
              <span class="iconfont icon-aixin"></span>
              <span>{{ item.note.like_count }}</span>
            </div>
          </div>
        </div>

        <div v-else></div>
         </router-link>
      </div>

    </div>
  </div>
</template>

<script>
import { getNoteDetail, getNoteRelated } from "../../api/node";
export default {
  data() {
    return {
      images: [],
      current: 0,
      story: [],
      notelists: [],
    };
  },
  methods: {
    onChange(index) {
      this.current = index;
    },
    prev() {
      this.$router.go(-1);
    },
    getNoteDetail(ids){
      getNoteDetail(ids).then((data) => {
        this.images = data.result.note.images;
        this.story.push(data.result.note);
        return ['this.images','this.story']
      })
    },
    getNoteRelated(ids){
       getNoteRelated(ids + "/0/20").then((data) => {
        this.notelists = data.result.list;
        console.log(data);
    });
    }
  },
  created() {
    let queryId = this.$route.query.id;
    console.log(queryId);
    getNoteDetail(queryId).then((data) => {
      this.images = data.result.note.images;
      this.story.push(data.result.note);
    });
    getNoteRelated(queryId + "/0/20").then((data) => {
      this.notelists = data.result.list;
      console.log(data);
    });
  },
  
  watch:{
   "$route.query"(){
     let queryId = this.$route.query;
     let ids = queryId.id;
     this.getNoteDetail(ids);
     this.getNoteRelated(ids)
      this.story.splice(0,1)
   }
  }
};
</script>

<style lang="less">
.custom-indicator {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 2px 10px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  color: white;
}
.note_header {
  width: 100%;
  height: 50px;
  position: fixed;
  top: 0;
  z-index: 1;
  background-color: white;
  .note_headtext {
    height: 100%;
    display: flex;
    align-items: center;
    .icon-fanhui {
      margin-left: 21px;
      font-size: 17px;
      line-height: 17px;
      color: black;
    }
    .img {
      width: 32px;
      height: 32px;
      margin-left: 23px;
      img {
        height: 100%;
        width: 100%;
        border-radius: 50%;
      }
    }
    .note_user {
      margin-left: 8px;
      div {
        p {
          font-size: 12px;
          line-height: 18px;
        }
      }
    }
    .note_guan {
      margin-left: 80px;
      background-color: #ffc533;
      border-radius: 20px;
      p {
        padding: 0px 18px;
        font-size: 12px;
        line-height: 28px;
      }
    }
    .icon-diandiandian {
      margin-left: 17px;
    }
  }
}
.note_img {
  width: 100%;
  margin-top: 50px;
  img {
    width: 100%;
    height: 100%;
  }
}
.note_name {
  margin: 0px 16px;
  margin-top: 30px;
  h2 {
    font-size: 16px;
    line-height: 16px;
  }
  .note_shao {
    margin-top: 14px;
    p {
      display: inline;
      font-size: 14px;
      line-height: 26px;
      align-items: center;
      span {
        align-items: center;
        img {
          display: inline;

          width: 12px;
          height: 12px;
        }
      }
    }
  }
  .note_time {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    p {
      font-size: 10px;
      line-height: 10px;
      color: #b6b6b6;
    }
  }
}

.h2 {
  margin-top: 63px;
  margin-left: 16px;
  font-size: 16px;
  line-height: 16px;
  font-weight: bold;
}
.node {
  margin: 18px 0px;
  // width: 100%;
  padding: 0px 5px;
  column-count: 2;
  column-gap: 10px;
  .good {
    width: 100%;
    margin-bottom: 10px;
    display: block;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    -webkit-column-break-inside: avoid;
    break-inside: avoid;
    counter-increment: item-counter;
    p {
      font-size: 14px;
      line-height: 30px;
      color: #231b0b;
      font-weight: bold;
      span {
        display: inline-block;
        color: black;
        font-size: 20px;
        line-height: 40px;
        margin-right: 16px;
      }
    }
    .good-img {
      width: 100%;
      .img {
        width: 100%;
        img {
          width: 100%;
          height: 100%;
          border-top-left-radius: 5px;
          border-top-right-radius: 5px;
        }
      }
      .pull {
        margin: 10px 0px;
        p {
          font-size: 13px;
          line-height: 20px;
          color: #181818;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
      .duo {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .duo-left {
          display: flex;
          img {
            width: 15px;
            height: 15px;
            border-radius: 50px;
            margin-right: 3px;
          }
          span {
            display: inline-block;
            font-size: 10px;
            line-height: 15px;
            color: #959595;
          }
        }
        .duo-right {
          display: flex;
          img {
            width: 15px;
            height: 15px;
          }
          span {
            display: inline-block;
            font-size: 10px;
            line-height: 15px;
            color: black;
            margin: 0 2px;
          }
        }
      }
    }
  }
}
</style>